/***********************************************************************
 * Module:  CommonConstant.java
 * Author:  Administrator
 * Purpose: Defines the Class CommonConstant
 ***********************************************************************/

package com.companyName.sample.common.util;

import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@SuppressWarnings("unchecked")
public class CommUtil {

	/** 是否抛异常标志 */
	public static final boolean throwFlag = true;

	/*--------------------------------------常用方法部分----begin-----------------------------------------------*/
	/** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%类型转换部分(1)[begin]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * */
	/**
	 * 判断两个对象是否相等，当为数字的时候1.00是等于1的所以特意写了函数
	 */
	public static boolean equals(Object obj1, Object obj2) {
		boolean retb = false;
		try {
			if ("0".equals(obj2) && !"0".equals(obj1)) {
				return false;
			}
			if (!"0".equals(obj2) && "0".equals(obj1)) {
				return false;
			}
			if (isDecimal(toString(obj1)) && isDecimal(toString(obj2))) {
				if (ObjectTodouble(obj1) == ObjectTodouble(obj2)) {
					return true;
				}
			} else {
				if (obj1.equals(obj2)) {
					return true;
				}
			}
		} catch (Exception e) {
		}
		return retb;
	}

	/**
	 * 将对象转换为String型
	 */
	public static String toString(Object obj) {
		try {
			if (obj instanceof Double) {
				String str = NumberFormat(obj);
				if (isNotEmpty(str)) {
					return str;
				}
			}
			if (obj instanceof Float) {
				String str = NumberFormat(obj);
				if (isNotEmpty(str)) {
					return str;
				}
			}
			obj = changeNull(obj);
			return String.valueOf(obj).trim();
		} catch (Exception e) {
			try {
				return obj.toString().trim();
			} catch (Exception e1) {
				try {
					return ((String) obj).trim();
				} catch (Exception e2) {
					return "";
				}
			}
		}
	}

	/**
	 * 将对象转换为String型
	 */
	public static String NumberFormat(Object obj) {
		try {
			NumberFormat df = NumberFormat.getNumberInstance();
			String num = df.format(obj);
			return num.replaceAll(",", "");
		} catch (Exception ex) {
			return "";
		}
	}

	/**
	 * 如果为null转换为空
	 */
	public static Object changeNull(Object obj) {
		if (obj == null || "null".equals(obj)) {
			return "";
		}
		return obj;
	}

	/**
	 * 如果检查对象为null报异常
	 */
	public static Object checkObjectNullThrow(Object obj) {
		if (obj == null || "null".equals(obj)) {
			throwInfoNotEmpty(obj);
		}
		return obj;
	}

	/**
	 * 如果检查对象为null或者为空报异常
	 */
	public static Object checkObjectEmptyThrow(Object obj) {
		if (obj == null || "null".equals(obj) || "".equals(obj)) {
			throwInfoNotEmpty(obj);
		}
		return obj;
	}

	/**
	 * 判断对象是否为null.<br>
	 */
	public static boolean isNull(Object obj) {
		if (obj == null || "null".equals(obj)) {
			return true;
		}
		return false;
	}

	/**
	 * 判断对象是否为空.<br>
	 */
	public static boolean isEmpty(Object obj) {
		if (obj == null || "null".equals(obj) || "".equals(obj)) {
			return true;
		}
		return false;
	}

	/**
	 * 判断对象是否为空.<br>
	 */
	public static boolean isNotEmpty(Object obj) {
		if (obj == null || "null".equals(obj) || "".equals(obj)) {
			return false;
		}
		return true;
	}

	/**
	 * 把字符串转化成int类型.<br>
	 */
	public static int StringToint(String strObj) {
		int value = 0;
		if (isEmpty(strObj)) {
			return 0;
		}
		try {
			value = StringToBigDecimal(strObj).intValue();
		} catch (Exception ex) {

		}
		return value;
	}

	/**
	 * 把对象转化成int类型.<br>
	 */
	public static int ObjectToint(Object obj) {
		int value = 0;
		String strObj = toString(obj);
		if (isEmpty(strObj)) {
			return 0;
		}
		try {
			value = StringToBigDecimal(strObj).intValue();
		} catch (Exception ex) {

		}
		return value;
	}

	/**
	 * 把字符串转化成double类型.<br>
	 */
	public static double ObjectTodouble(Object strObj) {
		double strValue = 0;
		strValue = StringTodouble(toString(strObj));
		return strValue;
	}

	/**
	 * 把字符串转化成double类型.<br>
	 */
	public static double StringTodouble(String strObj) {
		double strValue = 0;
		if (isEmpty(strObj)) {
			return 0;
		}
		try {
			strValue = Double.parseDouble(strObj);
		} catch (Exception ex) {
			strValue = 0;
		}
		return strValue;
	}

	/**
	 * 把字符串转化成float类型.<br>
	 */
	public static float StringTofloat(String strObj) {
		if (isEmpty(strObj)) {
			return 0;
		}
		return Float.parseFloat(strObj);
	}

	/**
	 * 把字符串转化成Integer类型.<br>
	 */
	public static Integer StringToInteger(String strObj) {
		Integer retInteger = new Integer(0);
		if (isEmpty(strObj)) {
			return new Integer(0);
		}
		try {
			int value = StringToBigDecimal(strObj).intValue();
			retInteger = new Integer(value);
		} catch (Exception ex) {
			return new Integer(0);
		}
		return retInteger;
	}

	/**
	 * 把字符串转化成Integer类型.<br>
	 */
	public static Integer ObjectToInteger(Object obj) {
		Integer retInteger = new Integer(0);
		String strObj = toString(obj);
		if (isEmpty(strObj)) {
			return new Integer(0);
		}
		try {
			int value = StringToBigDecimal(strObj).intValue();
			retInteger = new Integer(value);
		} catch (Exception ex) {
			return new Integer(0);
		}
		return retInteger;
	}

	/**
	 * 把字符串转化成Double类型.<br>
	 */
	public static Double StringToDouble(String strObj) {
		if (isEmpty(strObj)) {
			return new Double(0);
		}
		return Double.valueOf(strObj);
	}

	/**
	 * 把字符串转化成Decimal类型.<br>
	 */
	public static BigDecimal StringToBigDecimal(String strObj) {
		if (isEmpty(strObj)) {
			return new BigDecimal(0);
		}
		return new BigDecimal(strObj);
	}

	/**
	 * 把对象转化成Decimal类型.<br>
	 */
	public static BigDecimal ObjectToBigDecimal(Object obj) {
		String strObj = toString(obj);
		if (isEmpty(strObj)) {
			return new BigDecimal(0);
		}
		return new BigDecimal(strObj);
	}

	/**
	 * 把字符串转化成changeFloat类型.<br>
	 */
	public static Float StringTOFloat(String strObj) {
		if (isEmpty(strObj)) {
			return new Float(0);
		}
		return Float.valueOf(strObj);
	}

	/**
	 * 把BigDecimal转化成Integer类型.<br>
	 */
	public static Integer BigDecimalToInteger(BigDecimal strObj) {
		if (isEmpty(strObj)) {
			return new Integer(0);
		}
		return new Integer(strObj.intValue());
	}

	/**
	 * 把Integer转化成BigDecimal类型.<br>
	 */
	public static BigDecimal IntegerToBigDecimal(Integer strObj) {
		if (isEmpty(strObj)) {
			return new BigDecimal(0);
		}
		return new BigDecimal(toString(strObj));
	}

	/**
	 * 把Number转化成字符串类型.<br>
	 */
	public static String NumberToString(Object strObj) {
		String strRet = "";
		try {

			if (isEmpty(strObj)) {
				return "";
			}
			if (Double.parseDouble(strObj.toString()) == 0) {
				return "";
			}
			strRet = toString(strObj);
			double compareDou = Double.parseDouble(strRet);
			long compareInt = Math.round(compareDou);
			if (compareInt == compareDou) {
				strRet = toString(new Long(compareInt));
			}
		} catch (Exception e) {
			return "";
		}
		return strRet;
	}

	/** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%类型转换部分(1)[end]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * */

	/** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%判断对象部分(2)[begin]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * */
	/**
	 * 判断list只有一条记录
	 */
	public static boolean checkListOnlyNote(List list) {
		if (list != null && list.size() == 1) {
			return true;
		}
		return false;
	}

	/**
	 * 判断list多于一条记录或为空
	 */
	public static boolean checkListNotOnlyNote(List list) {
		if (list != null && list.size() == 1) {
			return false;
		}
		return true;
	}

	/**
	 * 判断list不为空
	 */
	public static boolean isNotEmptyList(List list) {
		if (list != null && !list.isEmpty() && list.size() > 0) {
			return true;
		}
		return false;
	}

	/**
	 * 判断list为空
	 */
	public static boolean isEmptyList(List list) {
		if (list == null) {
			list = new ArrayList();
		}
		if (list.isEmpty() || list.size() == 0) {
			return true;
		}
		return false;
	}

	/**
	 * 抛非null异常
	 */
	public static void throwInfoNotNull(Object obj) {
		if (throwFlag && (obj == null || "null".equals(obj))) {
			throw new IllegalArgumentException("参数不能为null。");
		}
	}

	/**
	 * 抛非空异常
	 */
	public static void throwInfoNotEmpty(Object obj) {
		if (throwFlag && (obj == null || "null".equals(obj) || "".equals(obj))) {
			throw new IllegalArgumentException("传入值不能为空。");
		}
	}

	/**
	 * 抛非空异常
	 */
	public static void throwInfoListOnly(List list) {
		if (throwFlag && list.size() != 1) {
			throw new IllegalArgumentException("该表中的记录不唯一或不存在。");
		}
	}

	/**
	 * 比较两个字符串是否相等，如果是数值型 "1.00" = "1"的<br>
	 */
	public static boolean comparePostLevelEquals(String postLevel1, String postLevel2) {
		boolean ret = false;
		double d1 = StringTodouble(postLevel1);
		double d2 = StringTodouble(postLevel2);
		if (d1 != 0 && d2 != 0) {
			if (d1 == d2) {
				return true;
			}
		} else {
			if (postLevel1.equals(postLevel2)) {
				return true;
			}
		}
		return ret;
	}

	/**
	 * 比较两个数字的大小。返回0代表相等；1前一个大；-1 前一个小<br>
	 */
	public static int compareNumber(String comp1, String comp2) {
		int ret = 0;
		double c1 = StringTodouble(comp1);
		double c2 = StringTodouble(comp2);
		if (c1 == c2)
			ret = 0;
		if (c1 > c2)
			ret = 1;
		if (c1 < c2)
			ret = -1;
		return ret;
	}

	/**
	 * 检查字串是否为数字
	 */
	public static boolean isNum(String Astr) {
		if (Astr == null || Astr.equals("") == true)
			return false;

		for (int i = 0; i < Astr.length(); i++) {
			if (Astr.charAt(i) > '9' || Astr.charAt(i) < '0')
				return false;
		}
		return true;
	}

	/**
	 * 正则表达式判断20位以内
	 */
	public static boolean isNumber(String str) {// 判断整数
		String digit = "20";
		String matches = "\\d{0," + digit + "}";
		return useMatches(str, matches);
	}

	/**
	 * 正则表达式判断小数
	 */
	public static boolean isDecimal(String str) {// 判断小数
		String befDigit = "32";
		String aftDigit = "32";
		if (isDecimal(str, befDigit, aftDigit) || isNumber(str, "32")) {
			return true;
		}
		return false;
	}

	/**
	 * 正则表达式判断4位小数
	 */
	public static boolean isDecimalForFour(String str) {// 判断小数
		String befDigit = "16";
		String aftDigit = "4";
		if (isDecimal(str, befDigit, aftDigit) || isNumber(str, "20")) {
			return true;
		}
		return false;
	}

	/**
	 * 正则表达式判断2位小数
	 */
	public static boolean isDecimalForTwo(String str) {// 判断小数
		String befDigit = "18";
		String aftDigit = "2";
		return isDecimal(str, befDigit, aftDigit);
	}

	/**
	 * 正则表达式判断小数.<br>
	 * befDigit前位数aftDigit后位数.
	 */
	public static boolean isDecimal(String str, String befDigit, String aftDigit) {// 判断小数
		String matches = "\\d{0," + befDigit + "}\\.\\d{0," + aftDigit + "}";
		return useMatches(str, matches);
	}

	/**
	 * 正则表达式判断digit位数
	 */
	public static boolean isNumber(String str, String digit) {// 判断整数
		String matches = "\\d{0," + digit + "}";
		return useMatches(str, matches);
	}

	/**
	 * 正则表达式判断基方法
	 */
	public static boolean useMatches(String context, String matches) {
		return context.matches(matches);
	}

	/** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%判断对象部分(2)[end]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * */

	/** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%编码处理部分(3)[begin]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * */
	/**
	 * 转码[ISO-8859-1 -> GBK] 不同的平台需要不同的转码
	 */
	public static String ISO8859toGBK(Object obj) {
		return codingChange(obj, "ISO-8859-1", "GBK");
	}

	/**
	 * 转码[ISO-8859-1 -> UTF-8] 不同的平台需要不同的转码
	 */
	public static String ISO8859toUTF(Object obj) {
		return codingChange(obj, "ISO-8859-1", "UTF-8");
	}

	/**
	 * 转码[GBK -> ISO-8859-1] 不同的平台需要不同的转码
	 */
	public static String GBKtoISO8859(Object obj) {
		return codingChange(obj, "GBK", "ISO-8859-1");
	}

	/**
	 * 转码[UTF-8 -> ISO-8859-1] 不同的平台需要不同的转码
	 */
	public static String UTFtoISO8859(Object obj) {
		return codingChange(obj, "UTF-8", "ISO-8859-1");
	}

	/**
	 * 编码互换
	 */
	public static String codingChange(Object obj, String fromCoding, String toCoding) {
		try {
			if (isEmpty(obj)) {
				return "";
			} else {
				String str = toString(obj);
				return new String(str.getBytes(fromCoding), toCoding);
			}
		} catch (Exception e) {
			return "";
		}
	}

	/** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%编码处理部分(3)[end]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * */

	/** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%日期处理部分(4)[begin]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * */
	/**
	 * 将字符串型转换为日期型 "yyyy-MM-dd HH:mm:ss" return:日期型
	 */
	public static Date dateParse(String datestr, String pattean) {
		Date date = null;
		try {
			java.text.DateFormat df = new SimpleDateFormat(pattean);
			date = df.parse(datestr);
		} catch (Exception ex) {
			return null;
		}
		return date;
	}

	/**
	 * 得到当前日期和时间(字符串型) "yyyy-MM-dd HH:mm:ss" return: 字符串型
	 */
	public static String dateFormat(String pattean, Date date) {
		String datestr = "";
		try {
			java.text.DateFormat df = new SimpleDateFormat(pattean);
			datestr = df.format(date);
		} catch (Exception ex) {
			return null;
		}
		return datestr;
	}

	/**
	 * 得到当前日期和时间(字符串型) "yyyy-MM-dd HH:mm:ss" return: 字符串型
	 */
	public static String dateFormat(String pattean) {
		String datestr = "";
		try {
			java.text.DateFormat df = new SimpleDateFormat(pattean);
			Date date = new Date();
			datestr = df.format(date);
		} catch (Exception ex) {
			return null;
		}
		return datestr;
	}

	/**
	 * 得到去年年份 格式 "yyyy"
	 */
	public static String getPreStrYear() {
		String datestr = (Integer.parseInt(dateFormat("yyyy")) - 1) + "";
		return datestr;
	}

	/**
	 * 得到去年年份 格式 "yyyy"
	 */
	public static String getStrAddYear(int num) {
		String datestr = (Integer.parseInt(dateFormat("yyyy")) + num) + "";
		return datestr;
	}

	/**
	 * 得到当前年份 格式 "yyyy"
	 */
	public static String getCurStrYear() {
		String datestr = dateFormat("yyyy");
		return datestr;
	}

	/**
	 * 得到当前月 格式 "yyyyMM"
	 */
	public static String getCurStrMonth() {
		String datestr = dateFormat("yyyyMM");
		return datestr;
	}

	/**
	 * 得到当前日期 格式 "yyyyMMdd"
	 */
	public static String getCurStrDay() {
		String datestr = dateFormat("yyyyMMdd");
		return datestr;
	}

	/**
	 * @param startDate 输入一日期格式"2006-06-06"
	 * @param addNumber startDate日期前或后多少天的日期，参数为正或负数
	 * @return startDate为2000-12-20，参数为10或-10得2000-12-30或2000-12-10
	 */
	public static String dateDiff(String startDate, int addNumber) {
		String dateEnd = "";
		if (startDate.length() > 10) {
			startDate = startDate.substring(0, 10);
		}
		try {
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
			Date dateStart = formatter.parse(startDate);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(dateStart);
			calendar.add(Calendar.DATE, addNumber);
			dateEnd = formatter.format(calendar.getTime());
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return dateEnd;
	}

	/**
	 * @param year 输入年份格式"2006"
	 * @param month 输入月份格式"06"
	 * @return changeday 该月的天数 如31
	 */
	public static String getDayNumber(String year, String month) {
		String changeday = "31";
		if (!"12".equals(month)) {
			String startDate = year + "-" + month + "-" + "01";
			String endDate = year + "-" + String.valueOf(Integer.parseInt(month) + 1) + "-" + "01";
			try {
				SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
				Date dateStart = formatter.parse(startDate);
				Date dateEnd = formatter.parse(endDate);
				Calendar calendar = Calendar.getInstance();
				calendar.setTime(dateStart);
				int startday = calendar.get(Calendar.DAY_OF_YEAR);
				calendar.setTime(dateEnd);
				int endday = calendar.get(Calendar.DAY_OF_YEAR);
				changeday = String.valueOf(endday - startday);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return changeday;
	}

	/** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%日期处理部分(4)[end]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * */

	/** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%字符串处理部分(5)[begin]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%>>>> * */

	/**
	 * 判断字符是否包含数字
	 */
	public static boolean isCompriseNumber(String str) {
		String comp = "012345678790";
		boolean ret = false;
		for (int i = 0; i < comp.length(); i++) {
			char ch = comp.charAt(i);
			if (str.indexOf(ch) >= 0) {
				ret = true;
				break;
			}
		}
		return ret;
	}

	/**
	 * 判断字符是否是数字
	 */
	public static boolean checkIsNumber(String str) {
		String comp = "012345678790";
		boolean ret = false;
		if (comp.indexOf(str) > 0) {
			return true;
		}
		return ret;
	}

	/**
	 * 判断字符是否是数字
	 */
	public static boolean checkIsNumber(char strChar) {
		String str = "" + strChar;
		return checkIsNumber(str);
	}

	/**
	 * 截取一字符串中的数字并返回数组
	 */
	public static List filtGetNumberList(String content) {
		List retList = new ArrayList();
		String especialStr = "-";
		String numStr = "";
		char current = ' ';
		for (int i = 0; i < content.length(); i++) {
			current = content.charAt(i);
			if (checkIsNumber(current) || especialStr.indexOf(current) >= 0) {
				numStr += current;
			} else {
				if (isCompriseNumber(numStr)) {
					retList.add(numStr);
				}
				numStr = "";
			}
		}
		return retList;
	}

	/**
	 * 取字符串的字节数
	 */
	public static int strLen(String sData) {
		String sVal = "";
		int iRet = 0;
		if (sData == null) {
			iRet = 0;
		} else {
			sVal = sData.trim();
			byte[] b = sVal.getBytes();
			iRet = b.length;
		}
		return iRet;
	}

	/**
	 * 根据给字长度判字符串是否超长并截断之
	 */
	public static String getString(String targetStr, int targetLen) {
		String ret = "";
		String sDot = "...";
		String sVal = "";
		String sTmp = "";

		if (targetStr != null) {
			targetStr = targetStr.trim();
			targetStr = ISO8859toGBK(targetStr);
			if (strLen(targetStr) <= targetLen) {
				ret = targetStr;
			} else {
				int num = targetLen - 3;
				for (int i = 0; i < targetStr.length(); i++) {
					sTmp = sTmp + targetStr.charAt(i);
					if (strLen(sTmp) <= num) {
						sVal = sTmp;
					} else {
						break;
					}
				}
				ret = sVal + sDot;
			}
		}
		return GBKtoISO8859(ret);
	}

	/**
	 * 截取字符串str 从strat开始 截取长度为 len 例如：strat=1 代表从第一个开始 subString("abcd",2,2) = "bc"
	 */
	public static String subStrLen(String str, int strat, int len) {
		if (str == null || "null".equals(str)) {
			return "";
		}
		if (str.length() <= len) {
			return str;
		}
		return str.substring(strat - 1, strat + len - 1);
	}

	/**
	 * 根据给字长度判字符串是否超长并截断之
	 */
	public static String subStrLen(String str, int len) {
		if (isEmpty(str)) {
			return "";
		}
		if (str.length() <= len) {
			return str;
		}
		String retStr = str.substring(0, len);
		return retStr;
	}

	/**
	 * 截取字符串str 从 beginIndex开始到整个字符串最后 如果报错返回空 当 beginIndex > endIndex的时候会报错
	 * @author guojun
	 * @createDate 2008-11-05
	 */
	public static String subString(String strTag, int beginIndex) {
		String ret = subString(strTag, beginIndex, strTag.length());
		return ret;
	}

	/**
	 * 截取字符串str 从strat开始 beginIndex 开始 到endIndex 如果报错返回空 当 beginIndex > endIndex的时候会报错
	 * @author guojun
	 * @createDate 2008-11-05
	 */
	public static String subString(String strTag, int beginIndex, int endIndex) {
		String ret = "";
		try {
			ret = strTag.substring(beginIndex, endIndex);
		} catch (Exception ex) {
		}
		return ret;
	}

	/**
	 * 根据开始字符和结束字符截取字符串在这两个之间的字符 例如：str="12@345@678@9" beginSepar = endSepar = "@" ：输出：345@678
	 * @author guojun
	 * @createDate 2008-11-05
	 */
	public static String trunString(String str, String beginSepar, String endSepar) {
		String ret = "";
		int beginIndex = str.indexOf(beginSepar) + beginSepar.length();
		int endIndex = 0;
		if (isNotEmpty(endSepar)) {
			endIndex = str.lastIndexOf(endSepar);
		} else {
			endIndex = str.length();
		}
		ret = subString(str, beginIndex, endIndex);
		return ret;
	}

	/**
	 * 根据开始字符和结束字符截取字符串获取两个字符串之间的字符串并用分号分割 例如：str="12@345@678@9ab@cd" beginSepar = endSepar = separ = "@" 输出：345;9ab、
	 * @author guojun
	 * @createDate 2008-11-05
	 */
	public static String trunStr(String str, String separ) {
		String ret = trunStr(str, separ, separ);
		return ret;
	}

	/**
	 * 根据开始字符和结束字符截取字符串获取两个字符串之间的字符串并用分号分割 例如：str="12@345#678@9ab#cd" beginSepar = "@" endSepar = "#" 输出：345;9ab
	 * @author guojun
	 * @createDate 2008-11-05
	 */
	public static String trunStr(String str, String beginSepar, String endSepar) {
		String ret = trunStrRecursion(str, beginSepar, endSepar, false);
		return ret;
	}

	/**
	 * 递归 调用截取字符串 导致不能再截取为止
	 * @author guojun
	 * @createDate 2008-11-05
	 */
	public static String trunStrRecursion(String str, String beginSepar, String endSepar, boolean isRepeat) {
		String ret = "";
		int beginIndex = str.indexOf(beginSepar);
		int endIndex = str.indexOf(endSepar, beginIndex + beginSepar.length());
		if (beginIndex == -1 || endIndex == -1) {
			return ret;
		}
		beginIndex = beginIndex + beginSepar.length();
		int index = endIndex + endSepar.length();
		String strRec = subString(str, index);
		// System.out.println(strRec + "(" + beginIndex + ")" + "(" + endIndex + ")");
		if (beginIndex < endIndex) {
			String ret1 = subString(str, beginIndex, endIndex);
			// 递归调用自己
			String ret2 = trunStrRecursion(strRec, beginSepar, endSepar, isRepeat);
			if (ret2.indexOf(ret1) >= 0 && !isRepeat) { // 如果在 ret2 中存在相同的 ret1
				// 则不加入到字符串
				ret1 = "";
			}
			ret = ret1 + " " + ret2;
		}
		return ret;
	}

	/**
	 * 根据开始字符和结束字符截取字符串获取两个字符串之间的字符串并用分号分割 例如：str="12@345#678@9ab#cd" beginSepar = "@" endSepar = "#" 输出：List = {345;9ab}
	 * @author guojun
	 * @createDate 2008-11-05
	 */
	public static List trunStrRecList(String str, String separ) {
		List ret = trunStrRecList(str, separ, separ, false);
		return ret;
	}

	/**
	 * 根据开始字符和结束字符截取字符串获取两个字符串之间的字符串并用分号分割 例如：str="12@345#678@9ab#cd" beginSepar = "@" endSepar = "#" 输出：List = {345;9ab}
	 * @author guojun
	 * @createDate 2008-11-05
	 */
	public static List trunStrRecList(String str, String beginSepar, String endSepar) {
		List ret = trunStrRecList(str, beginSepar, endSepar, false);
		return ret;
	}

	/**
	 * 递归 调用截取字符串 导致不能再截取为止 返回list
	 * @author guojun
	 * @createDate 2008-11-07
	 */
	public static List trunStrRecList(String str, String beginSepar, String endSepar, boolean isRepeat) {
		List list = new ArrayList();
		int beginIndex = str.indexOf(beginSepar);
		int endIndex = str.indexOf(endSepar, beginIndex + beginSepar.length());
		if (beginIndex == -1 || endIndex == -1) {
			return list;
		}
		beginIndex = beginIndex + beginSepar.length();
		int index = endIndex + endSepar.length();
		String strRec = subString(str, index);
		if (beginIndex < endIndex) {
			String ret1 = subString(str, beginIndex, endIndex);
			// 递归调用自己
			List list2 = trunStrRecList(strRec, beginSepar, endSepar, isRepeat);
			if (listExistElem(list2, ret1) && !isRepeat) { // 如果在 ret2 中存在相同的 ret1
				ret1 = "";// 则不加入到字符串
			}
			if (!"".equals(ret1))
				list.add(ret1);
			list.addAll(list2);
		}
		return list;
	}

	/**
	 * 获取两个字符之间的值beginSign endSign 并返回 map
	 */
	public static Map trunStrRecMap(String content, char beginSign, char endSign) {
		char curr = ' ';
		String value = "";
		boolean newValue = false;
		Map retMap = new HashMap();
		for (int i = 0; i < content.length(); i++) {
			curr = content.charAt(i);
			if (curr == beginSign && (!newValue)) {
				newValue = true;
				value = "";
			} else if (curr != endSign && newValue && curr != ' ') {
				value = value + curr;
			} else if (curr == endSign && newValue) {
				newValue = false;
				retMap.put(value, "" + i);
			}
		}
		return retMap;
	}

	/**
	 * 获取sign字符之间的值 并返回 map
	 */
	public static Map trunStrRecMap(String content, char sign) {
		Map retMap = trunStrRecMap(content, sign, sign);
		return retMap;
	}

	/**
	 * 检查list里面是否存在改对象
	 * @author guojun
	 * @createDate 2008-11-05
	 */
	public static boolean listExistElem(List list, Object obj) {
		for (int i = 0; i < list.size(); i++) {
			Object o = list.get(i);
			if (o.equals(obj)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 根据分隔符截取返回String[] 字符串转数组
	 * @author guojun
	 * @createDate 2008-11-06
	 */
	public static String[] splitArr(String tagStrs, String separ) {
		List list = splitList(tagStrs, separ);
		String[] retsArr = new String[list.size()];
		for (int i = 0; i < list.size(); i++) {
			retsArr[i] = toString(list.get(i));
		}
		return retsArr;
	}

	/**
	 * 根据分隔符截取返回List 字符串转数组 没有通过String的split()方法主要是参考了jdk，提高效率
	 * @author guojun
	 * @createDate 2008-11-06
	 */
	public static List splitList(String tagStrs, String separ) {
		tagStrs = toString(tagStrs);
		List retsList = new Vector();
		while (tagStrs.length() != 0) {
			int x = tagStrs.indexOf(separ);
			if ("".equals(separ)) {// 如果separ = "" 的时候就按照每个字符分割
				x = 1;
			}
			String tagStr = "";
			if (x < 0) {
				tagStr = tagStrs;
				tagStrs = "";
			} else {
				tagStr = tagStrs.substring(0, x);
				tagStrs = tagStrs.substring(x + separ.length());
			}
			if (tagStr.length() == 0) {
				continue;
			}
			retsList.add(tagStr);
		}
		return retsList;
	}

	/**
	 * 右填充字符串str，长度为length，填充字符为sign
	 */
	public static String rpad(String str, int length, char sign) {
		String reStr = str;
		int len = str.getBytes().length;
		if (len >= length) {
			return reStr;
		}
		for (int i = 0; i < length - len; i++) {
			reStr += sign;
		}
		return reStr;
	}

	/**
	 * 左填充字符串str，长度为length，填充字符为sign
	 */
	public static String lpad(String str, int length, char sign) {
		String reStr = str;
		int len = str.getBytes().length;
		if (len >= length) {
			return reStr;
		}
		for (int i = 0; i < length - len; i++) {
			reStr = sign + reStr;
		}
		return reStr;
	}

	/**
	 * 右填充字符串str，长度为length，填充字符串为sign
	 */
	public static String rpad(String str, int length, String sign) {
		String reStr = str;
		int len = str.getBytes().length;
		int addStrLen = sign.getBytes().length;

		if (len >= length) {
			return reStr;
		}
		for (int i = 0; i < (length - len) / addStrLen; i++) {
			reStr += sign;
		}
		reStr = rpad(reStr, length, ' ');
		return reStr;
	}

	/**
	 * 左填充字符串str，长度为length，填充字符串为sign
	 */
	public static String lpad(String str, int length, String sign) {
		String reStr = str;
		int len = str.getBytes().length;
		int addStrLen = sign.getBytes().length;
		if (len >= length) {
			return reStr;
		}
		for (int i = 0; i < (length - len) / addStrLen; i++) {
			reStr = sign + reStr;
		}
		reStr = lpad(reStr, length, ' ');
		return reStr;
	}

	/**
	 * 用正则表达式判断字符串中有中文String str = "asdfas大幅度df";
	 */
	public boolean strinzh(String str) {
		java.util.regex.Pattern p = java.util.regex.Pattern.compile("[\u4e00-\u9fa5]");
		java.util.regex.Matcher m = p.matcher(str);
		if (m.find()) {// 含有中文
			return true;
		} else {// 没有中文
			return false;
		}
	}

	/**
	 * 字符串中提炼出数字 输入一带数字的字符串。 只提炼出数字返回； 例如：32adc6e.d8cc --> 326.8
	 */
	public String getNumber(String str) {
		StringBuffer strbuf = new StringBuffer();
		for (int i = 0; i < str.length(); i++) {
			char c = str.charAt(i);
			if (c >= '0' && c <= '9' || c == '.') {
				strbuf.append(c);
			}
		}
		return strbuf.toString();
	}

	/**
	 * 替换字符串 目标：regex 源：replacement
	 */
	public static String replaceAll(String tagStr, String regex, String replacement) {
		String ret = tagStr;
		try {
			ret = tagStr.replaceAll(regex, replacement);
		} catch (Exception ex) {
		}
		return ret;
	}

	/**
	 * 获取Map的第一行的value值
	 */
	public static Object getMapFirstValue(Map map) {
		Object obj = map.get(getMapFirstKey(map));
		return obj;
	}

	/**
	 * 获取Map的第一行的value值
	 */
	public static Object getMapFirstKey(Map map) {
		Object reStr = "";
		Iterator it = map.keySet().iterator();
		while (it.hasNext()) {
			reStr = it.next();
		}
		return reStr;
	}

	/**
	 * 获取Map的第一行的value值 object
	 */
	public static Object getListMapFirstValueObj(List list) {
		if (list.size() > 0) {
			Map map = ((Map) list.get(0));
			Object obj = getMapFirstValue(map);
			return obj;
		}
		return "";
	}

	/**
	 * 获取Map的第一行的value值String
	 */
	public static String getListMapFirstValueStr(List list) {
		return toString(getListMapFirstValueObj(list));
	}

	/** <<<<%%%%%%%%%%%%%%%%%%%%%%%%%%%%%字符串处理部分(5)[end]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * */

	/** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%对象复制部分(6)[begin]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%>>>> * */
	/**
	 * 将对象source复制到对象target
	 */
	public static void copyProperties(Object source,Object target) {
		if(source != null){
			BeanUtils.copyProperties(source, target);
		}
	}

	/** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%对象复制部分(6)[end]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * */
}